using System;
using Common.Enumerations;
using Sanelib.Common.Extensions;
using Sanelib.Dto;

namespace Common.Commands.FolderCommands
{
    public class AddFolder : AuditedCommand
    {
        public Guid ReferenceId { get; set; }
        public string ReferenceName { get; set; }
        public string Tags { get; set; }
        public EntityType EntityType { get; set; }

        public override Guid? GetAggregateId()
        {
            return ReferenceId;
        }

        public override ErrorResult Validate()
        {
            var validationResult = new ErrorResult();
            
            if (!string.IsNullOrWhiteSpace(Name) && Name.Length > 256)
                validationResult.AddError("Name", " entered exceeds the maximum length 256");

            if (Name.IsEmpty())
                validationResult.AddError("Name", "should not be empty");
            
            if (ReferenceId.IsEmpty())
                validationResult.AddError("Account Name", "should be selected.");

            if (Tags.IsEmpty())
                validationResult.AddError("Tags", "should not be empty.");
            
            if (!string.IsNullOrWhiteSpace(Description) && Description.Length > 2048)
                validationResult.AddError("Description", " entered exceeds the maximum length 2048");

            return validationResult;
        }
    }
}